﻿Public Class ForMoreExtraservice
    Dim DAService As New DSReservationTableAdapters.OTHER_SERVICESTableAdapter
    Dim DAReservationDetail As New DSReservationTableAdapters.RESERVATION_DETAILTableAdapter
    Dim Reservation As MainReservation
    Sub New(ByVal Reservation As MainReservation)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        Me.Reservation = Reservation
        With CboService
            .DataSource = DAService.GetData
            .ValueMember = "SERVICE_ID"
            .DisplayMember = "SERVICE_NAME"
            .SelectedIndex = -1
        End With
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Me.Close()
    End Sub

    Private Sub ForMoreExtraservice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        If ValidateCombobox(CboService, "", ErrExtrarService) = False Then Exit Sub
        If ValidateTextField(TxtServicePrice, "", ErrExtrarService) = False Then Exit Sub
        If ValidateTextField(TxtQTY, "", ErrExtrarService) = False Then Exit Sub
        If MessageBox.Show("Do you want to save more service", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            If DAReservationDetail.InsertNewReservation(lblReservationID.Text, CboService.SelectedValue, CboService.Text, EmptyString(TxtQTY.Text), EmptyString(TxtServicePrice.Text), EmptyString(TxtServicePrice.Text) * EmptyString(TxtQTY.Text)) = 1 Then
                Reservation.RefreshReservationDetail(lblReservationID.Text)
                CboService.SelectedIndex = -1
                TxtQTY.Text = ""
                TxtServicePrice.Text = ""
                Me.DialogResult = Windows.Forms.DialogResult.OK
            End If
        End If

    End Sub

    Private Sub TxtServicePrice_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtServicePrice.KeyPress
        SetDisableKeyString(e)
    End Sub

    Private Sub TxtQTY_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtQTY.KeyPress
        SetDisableKeyString(e)
    End Sub

    
    Private Sub CboService_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboService.SelectedIndexChanged
        Try
            TxtServicePrice.Text = DAService.SelectServicePrice(CboService.SelectedValue)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub TxtQTY_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtQTY.KeyUp
        If EmptyString(TxtQTY.Text) <= 0 Then
            MessageBox.Show("សូមមេត្តា ចំនួនធំជាងតម្លៃ 0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            TxtQTY.Text = ""
        End If
    End Sub
End Class